// Common/CommandLineParser.h

#ifndef __COMMON_COMMAND_LINE_PARSER_H
#define __COMMON_COMMAND_LINE_PARSER_H

#include "Common/MyFixes.h"

namespace GUI
{
namespace App
{

bool SplitCommandLine(const CString &src, CString &dest1, CString &dest2);
void SplitCommandLine(const CString &s, CStringVector &parts);

  enum class SwitchType
  {
    kSimple,
    kPostMinus,
    kLimitedPostString,
    kUnLimitedPostString,
    kPostChar
  };

struct CSwitchForm
{
  LPCTSTR IDString;
  SwitchType Type;
  bool Multi;
  int MinLen;
  int MaxLen;
  LPCTSTR PostCharSet;
};

struct CSwitchResult
{
  bool ThereIs;
  bool WithMinus;
  CStringVector PostStrings;
  int PostCharIndex;
  CSwitchResult(): ThereIs(false) {};
};
  
class CCmdLineParser
{
  int _numSwitches;
  CSwitchResult *_switches;
  bool ParseString(const CString &s, const CSwitchForm *switchForms);
public:
  CStringVector NonSwitchStrings;
  CCmdLineParser(int numSwitches);
  ~CCmdLineParser();
  void ParseStrings(const CSwitchForm *switchForms,
    const CStringVector &commandStrings);
  const CSwitchResult& operator[](size_t index) const;
};

/////////////////////////////////
// Command parsing procedures

struct CCommandForm
{
  LPCTSTR IDString;
  bool PostStringMode;
};

// Returns: Index of form and postString; -1, if there is no match
int ParseCommand(int numCommandForms, const CCommandForm *commandForms,
    const CString &commandString, CString &postString);

}
}
#endif
